package com.exporter.listeners;

import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import com.exporter.utility.ConfigurationLoader;

public class ToggleSftpOptionListener implements ItemListener
{
        
        JLabel lblSftpHost;
        JTextField txtSftpHost;
        JLabel lblsftpPort;
        JTextField txtSftpPort;
        JLabel lblUserName;
        JTextField txtUserName;
        JLabel lblPassword;
        JPasswordField txtPassword;
        JLabel lblUploadPath;
        JTextField txtUploadPath;
        JPanel sprSftpDetails;
        TitledBorder border;
        
        public ToggleSftpOptionListener(JPanel sprSftpDetails,
                                        JLabel lblSftpHost,
                                        JTextField txtSftpHost,
                                        JLabel lblsftpPort,
                                        JTextField txtSftpPort,
                                        JLabel lblUserName,
                                        JTextField txtUserName,
                                        JLabel lblPassword,
                                        JPasswordField txtPassword,
                                        JLabel lblUploadPath,
                                        JTextField txtUploadPath,
                                        TitledBorder border)
        {
                this.sprSftpDetails = sprSftpDetails;
                this.lblSftpHost = lblSftpHost;
                this.txtSftpHost = txtSftpHost;
                this.lblsftpPort = lblsftpPort;
                this.txtSftpPort = txtSftpPort;
                this.lblUserName = lblUserName;
                this.txtUserName = txtUserName;
                this.lblPassword = lblPassword;
                this.txtPassword = txtPassword;
                this.lblUploadPath = lblUploadPath;
                this.txtUploadPath = txtUploadPath;
                this.border = border;
        }

        @Override
        public void itemStateChanged(ItemEvent ie)
        {
            if(ie.getStateChange() == ItemEvent.SELECTED)
            {
                border.setTitleColor( Color.black );
                sprSftpDetails.setEnabled(true);
                lblSftpHost.setEnabled(true);
                txtSftpHost.setEnabled(true);
                txtSftpHost.setText( ConfigurationLoader.HOST_IP );
                lblsftpPort.setEnabled(true);
                txtSftpPort.setEnabled(true);
                txtSftpPort.setText( ConfigurationLoader.HOST_PORT );
                lblUserName.setEnabled(true);
                txtUserName.setEnabled(true);
                txtUserName.setText( ConfigurationLoader.HOST_USER );
                lblPassword.setEnabled(true);
                txtPassword.setEnabled(true);
                txtPassword.setText( ConfigurationLoader.HOST_PASSWORD );
                lblUploadPath.setEnabled(true);
                txtUploadPath.setEnabled(true);
                txtUploadPath.setText( ConfigurationLoader.FOLDER_UPLOAD_PATH );
            }
            else
            {
                border.setTitleColor( Color.gray );
                sprSftpDetails.setEnabled(false);
                lblSftpHost.setEnabled(false);
                txtSftpHost.setEnabled(false);
                txtSftpHost.setText( "" );
                lblsftpPort.setEnabled(false);
                txtSftpPort.setEnabled(false);
                txtSftpPort.setText( "" );
                lblUserName.setEnabled(false);
                txtUserName.setEnabled(false);
                txtUserName.setText( "" );
                lblPassword.setEnabled(false);
                txtPassword.setEnabled(false);
                txtPassword.setText( "" );
                lblUploadPath.setEnabled(false);
                txtUploadPath.setEnabled(false);
                txtUploadPath.setText( "" );
            }
        }

}
